package com.yzf.demo.demo.DesignPattren.SingletonPattern.staticInnersingleton;

/**
 * Created by 于占峰 on 2020/2/27/027.
 * 内部类单例模式
 */
public class StaticInnerSingleton {

    private StaticInnerSingleton() {
        //加入判断,重复创建抛出异常
        if (null != InerClass.staticInnerSingleton) {
            throw new RuntimeException("小伙子不可乱搞哦~");
        }
    }

    private static final StaticInnerSingleton getInstance() {
        return InerClass.staticInnerSingleton;
    }

    private static class InerClass {
        private static final StaticInnerSingleton staticInnerSingleton = new StaticInnerSingleton();
    }
}
